#!/bin/bash

master=10.2.20.46
slave1=10.2.20.32
slave2=10.2.20.39

if [ $# -ne 2 ] && [ ! -f $1 ]; then
	echo "no hadoop tar file."
	exit 1
fi

hadoop_filename=$(basename $1 )
echo "hadoop tar file name is ${hadoop_filename}"

echo "copy hadoop tar file"
for host in "$master" "$slave1" "$slave2"; do
	scp $1 uos@${host}:~/
	ssh uos@${host} "sudo tar xzvf ${hadoop_filename} -C /opt && sudo chown -R uos /opt/hadoop* && rm -f ${hadoop_filename}"
done

echo "set JAVA_HOME, HADOOP_HOME"
for host in "$master" "$slave1" "$slave2"; do
	cat bashrc | ssh uos@${host} "tee -a ~/.bashrc"
done
